C++ Technical Report 1

C++ Technical Report 1 (TR1) is the common name for ISO/IEC TR 19768, C++ Library Extensions, which was a document proposing additions to the C++ standard library for the C++03 language standard. The additions include regular expressions, smart pointers, hash tables, and random number generators. TR1 is not a standard itself, but rather a draft document. However, most of its proposals became part of the current official standard, C++11. Before C++11 was standardized, vendors used this document as a guide to create extensions. The report's goal is "to build more widespread existing practice for an expanded C++ standard library."

Contents

Overview

Compilers need not include the TR1 components to be conforming, as the TR1 proposals are not yet officially part of the standard. Much of it is available from Boost, and several compiler/library distributors currently implement all or part of the components.

TR1 is not a complete list of additions to the library that appear in the next standard; for example, the current standard, C++11, supports threading. There is also a second technical report, C++ Technical Report 2, planned for publishing after C++11 [1].

The new components are in the std::tr1 namespace to distinguish them from the current standard library.

Components

TR1 includes the following components:

General utilities

Reference wrapper

A wrapper reference is obtained from an instance of the template class reference_wrapper. Wrapper references are similar to normal references (‘&’) of the C++ language. To obtain a wrapper reference from any object the template class ref is used (for a constant reference cref is used).

Wrapper references are useful above all for template functions, when argument deduction would not deduce a reference (e.g. when forwarding arguments):

#include <iostream>
#include <tr1/functional>
 
void f( int &r )  { ++r; }
 
template< class Funct, class Arg >
void g( Funct f, Arg t )
{
  f(t);
}
 
int main()
{
  int i = 0;
 
  g( f, i );                   // 'g< void(int &r), int >' is instantiated
  std::cout << i << "\n";      // Output: 0
 
  g( f, std::tr1::ref(i) );    // 'g< void(int &r), reference_wrapper<int> >' is instanced
  std::cout << i << "\n";      // Output: 1
}

Smart pointers

Function objects

These four modules are added to the <functional> header file:

Polymorphic function wrapper

Function object binders

Function return types

mem_fn

Metaprogramming and type traits

Numerical facilities

Random number generation

Mathematical special functions

Some features of TR1, such as the mathematical special functions and certain C99 additions, are not included in the Visual C++ implementation of TR1. The Mathematical special functions library was not standardized in C++11.

These functions will likely be of principal interest to programmers in the engineering and scientific disciplines.

The following table shows all 23 special functions described in TR1.

Function name Function prototype Mathematical expression
Associated Laguerre polynomials double assoc_laguerre( unsigned n, unsigned m, double x ) ; {L_n}^m(x) = (-1)^m \frac{d^m}{dx^m} L_{n%2Bm}(x), \text{ for } x \ge 0
Associated Legendre polynomials double assoc_legendre( unsigned l, unsigned m, double x ) ; {P_l}^m(x) = (1-x^2)^{m/2} \frac{d^m}{dx^m} P_l(x), \text{ for } x \ge 0
Beta function double beta( double x, double y ) ; \Beta(x,y)=\frac{\Gamma(x) \Gamma(y)}{\Gamma(x%2By)}
Complete elliptic integral of the first kind double comp_ellint_1( double k ) ; K(k) = F\left(k, \textstyle \frac{\pi}{2}\right) = \int_0^{\frac{\pi}{2}} \frac{d\theta}{\sqrt{1 - k^2 \sin^2 \theta}}
Complete elliptic integral of the second kind double comp_ellint_2( double k ) ; E\left(k, \textstyle \frac{\pi}{2}\right) = \int_0^{\frac{\pi}{2}} \sqrt{1 - k^2 \sin^2 \theta}\; d\theta
Complete elliptic integral of the third kind double comp_ellint_3( double k, double nu ) ; \Pi\left(\nu, k, \textstyle \frac{\pi}{2}\right) = \int_0^{\frac{\pi}{2}} \frac{d\theta}{(1 - \nu \sin^2 \theta)\sqrt{1 - k^2 \sin^2 \theta}}
Confluent hypergeometric functions double conf_hyperg( double a, double c, double x ) ; F(a, c, x) = \frac{\Gamma(c)}{\Gamma(a)} \sum_{n = 0}^\infty \frac{\Gamma(a %2B n) x^n}{\Gamma(c %2B n) n!}
Regular modified cylindrical Bessel functions double cyl_bessel_i( double nu, double x ) ; I_\nu(x) = i^{-\nu} J_\nu(ix) = \sum_{k = 0}^\infty \frac{(x/2)^{\nu %2B 2k}}{k! \; \Gamma(\nu %2B k %2B 1)}, \text{ for } x \ge 0
Cylindrical Bessel functions of the first kind double cyl_bessel_j( double nu, double x ) ; J_\nu(x) = \sum_{k = 0}^\infty \frac{(-1)^k \; (x/2)^{\nu %2B 2k}}{k! \; \Gamma(\nu %2B k %2B 1)}, \text{ for } x \ge 0
Irregular modified cylindrical Bessel functions double cyl_bessel_k( double nu, double x ) ; \begin{align}
K_\nu(x) & = \textstyle\frac{\pi}{2} i^{\nu%2B1} \big(J_\nu(ix) %2B i N_\nu(ix)\big) \\
         & = \begin{cases}
                 \displaystyle \frac{I_{-\nu}(x) - I_\nu(x)}{\sin \nu\pi}, & \text{for } x \ge 0 \text{ and } \nu \notin \mathbb{Z} \\[10pt]
                 \displaystyle \frac{\pi}{2} \lim_{\mu \to \nu} \frac{I_{-\mu}(x) - I_\mu(x)}{\sin \mu\pi}, & \text{for } x < 0 \text{ and } \nu \in \mathbb{Z} \\
             \end{cases}
\end{align}
Cylindrical Neumann functions

Cylindrical Bessel functions of the second kind

double cyl_neumann( double nu, double x ) ; 
N_\nu(x) = \begin{cases}
                 \displaystyle \frac{J_\nu(x)\cos \nu\pi - J_{-\nu}(x)}{\sin \nu\pi}, & \text{for } x \ge 0 \text{ and } \nu \notin \mathbb{Z} \\[10pt]
                 \displaystyle \lim_{\mu \to \nu} \frac{J_\mu(x)\cos \mu\pi - J_{-\mu}(x)}{\sin \mu\pi}, & \text{for } x < 0 \text{ and } \nu \in \mathbb{Z} \\
             \end{cases}
Incomplete elliptic integral of the first kind double ellint_1( double k, double phi ) ; F(k,\phi)=\int_0^\phi\frac{d\theta}{\sqrt{1-k^2\sin^2\theta}}, \text{ for } \left|k\right| \le 1
Incomplete elliptic integral of the second kind double ellint_2( double k, double phi ) ; \displaystyle E(k,\phi)=\int_0^\phi\sqrt{1-k^2\sin^2\theta}d\theta, \text{ for } \left|k\right| \le 1
Incomplete elliptic integral of the third kind double ellint_3( double k, double nu, double phi ) ; \Pi(k,\nu,\phi)=\int_0^\phi\frac{d\theta}{\left(1-\nu\sin^2\theta\right)\sqrt{1-k^2\sin^2\theta}}, \text{ for } \left|k\right| \le 1
Exponential integral double expint( double x ) ;  \mbox{E}i(x)=-\int_{-x}^{\infty} \frac{e^{-t}}{t}\, dt
Hermite polynomials double hermite( unsigned n, double x ) ; H_n(x)=(-1)^n e^{x^2}\frac{d^n}{dx^n}e^{-x^2}\,\!
Hypergeometric series double hyperg( double a, double b, double c, double x ) ; F(a,b,c,x)=\frac{\Gamma(c)}{\Gamma(a)\Gamma(b)}\sum_{n = 0}^\infty\frac{\Gamma(a%2Bn)\Gamma(b%2Bn)}{\Gamma(c%2Bn)}\frac{x^n}{n!}
Laguerre polynomials double laguerre( unsigned n, double x ) ; L_n(x)=\frac{e^x}{n!}\frac{d^n}{dx^n}\left(x^n e^{-x}\right), \text{ for } x \ge 0
Legendre polynomials double legendre( unsigned l, double x ) ; P_l(x) = {1 \over 2^l l!} {d^l \over dx^l } (x^2 -1)^l, \text{ for } \left|x\right| \le 1
Riemann zeta function double riemann_zeta( double x ) ; 
\Zeta(x) =
          \begin{cases}
                 \displaystyle \sum_{k = 1}^\infty k^{-x}, & \text{for } x > 1 \\[10pt]
                 \displaystyle 2^x\pi^{x-1}\sin\left(\frac{x\pi}{2}\right)\Gamma(1-x)\zeta(1-x), & \text{for } x < 1 \\
             \end{cases}
Spherical Bessel functions of the first kind double sph_bessel( unsigned n, double x ) ; j_n(x) = \sqrt{\frac{\pi}{2x}} J_{n%2B1/2}(x), \text{ for } x \ge 0
Spherical associated Legendre functions double sph_legendre( unsigned l, unsigned m, double theta ) ;  Y_{l}^{m}(\theta, 0) \text{ where } Y_{l}^{m}(\theta, \phi) = (-1)^{m}\left[\frac{(2l%2B1)}{4\pi}\frac{(l-m)!}{(l%2Bm)!}\right]^{1 \over 2} P_{l}^{m}(\cos \theta)e^{\mathrm{i}m\phi}, \text{ for } |m| \leq l
Spherical Neumann functions

Spherical Bessel functions of the second kind

double sph_neumann( unsigned n, double x ) ; n_n(x) = \left(\frac{\pi}{2x}\right)^{\frac{1}{2}}N_{n%2B\frac{1}{2}}(x), \text{ for } x \ge 0

Each function has two additional variants. Appending the suffix ‘f’ or ‘l’ to a function name gives a function that operates on float or long double values respectively. For example:

float sph_neumannf( unsigned n, float x ) ;
long double sph_neumannl( unsigned n, long double x ) ;

Containers

Tuple types

Fixed size array

Hash tables

Regular expressions

C compatibility

C++ is designed to be compatible with the C programming language, but is not a strict superset of C due to diverging standards. TR1 attempts to reconcile some of these differences through additions to various headers in the C++ library, such as <complex>, <locale>, <cmath>, etc. These changes help to bring C++ more in line with the C99 version of the C standard (not all parts of C99 are included in TR1).

Technical Report 2

In 2005 a request for proposals for a TR2 was made with a special interest in Unicode, XML/HTML, Networking and usability for novice programmers.[3].

Some of the proposals include:

See also

References

External links

References

  1. ^ http://www.boost.org/doc/html/ref.html
  2. ^ http://www.boost.org/libs/smart_ptr/smart_ptr.htm
  3. ^ http://www.boost.org/doc/html/function.html
  4. ^ http://www.boost.org/libs/bind/bind.html
  5. ^ http://www.boost.org/libs/bind/mem_fn.html
  6. ^ http://www.boost.org/libs/tuple/doc/tuple_users_guide.html
  7. ^ http://www.boost.org/doc/html/array.html
  8. ^ http://www.boost.org/doc/libs/1_36_0/libs/regex/doc/html/index.html